home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / BUSINESS / TAS206.ARJ / ARRAYS.TAS next >
Text File  |  1991-01-07  |  3KB  |  50 lines

  1. { arrays.tas
  2.         This example shows how you can do arithmetic operations on
  3.         data arrays.
  4.         It creates an average of 3 momentum arrays. Then it creates
  5.         a 50 day EMA of the average momentum. Then it creates a 20
  6.         day EMA of the 50 day EMA.
  7.  
  8.         Thanks to Dan Rembolt for the example.
  9. }
  10. if quote_count>75 then          { Only do the following on tickers
  11.                                   containing at least 75 quotes }
  12. BEGIN                           { use BEGIN to group the following
  13.                                   statements until the next matching
  14.                                   END statment }
  15. mo75 : array;                   { declare an array named 'mo75' }
  16. mo20 : array;                   { declare an array named 'mo20' }
  17. mo10 : array;                   { declare an array named 'mo10' }
  18. mosum : array;                  { declare an array named 'mosum' }
  19. smoothmo : array;               { declare an array named 'smoothmo' }
  20. mo75 := mo(75);                 { compute the 75 day momentum and place
  21.                                   it in the 'mo75' array }
  22. mo20 := mo(20);                 { and then the 20 day momentum}
  23. mo10 := mo(10);                 { and finally the 10 day momentum }
  24. mosum := add(mo75,mo20);        { now, add 75 day momentum to 20 day
  25.                                   momentum. Place the result in array
  26.                                   'mosum'}
  27. mosum := add(mosum,mo10);       { add the 10 day momentum to 'mosum' array
  28.                                   so that now, 'mosum' contains the sum
  29.                                   of the three momenta}
  30. mosum := divby(mosum,3);        { DIVBY divides the first argument (the
  31.                                   array) by the second argument (the
  32.                                   number). So, in this case, mosum will
  33.                                   be the average of the three momentum
  34.                                   arrays previously added}
  35. smoothmo := mov(mosum,50,'E');  { Now, create a 50 day Exponential Moving
  36.                                   Average and place the resulting array
  37.                                   in "smoothmo"}
  38. moma := mov(smoothmo,20,'E');   { And, lastly, create a 20 day EMA of
  39.                                   the 50 day ema of the average of the
  40.                                   three momentum calculations }
  41.  
  42. writeln(ticker,' ',moma);
  43. { Alternatively, you can group the function calls together to make 
  44.   more complex calculations. The above calculation could also be 
  45.   written as follows:
  46. }
  47. moma := mov(mov(divby(add(add(mo(75),mo(20)),mo(10)),3),50,'e'),20,'e');
  48. writeln(ticker,' ',moma);
  49. END;
  50.